package com.soft.service.impl;

import java.util.List;

import com.soft.dao.PermissionDao;
import com.soft.model.UserPermission;
import com.soft.service.IUserPermissionService;
import com.soft.util.Const;

public class UserPermissionServiceImpl implements IUserPermissionService{

	@Override
	public List<UserPermission> findByUserId(int userId) {
		String sql = "select id, userId, pid from "+Const.USER_PERMISSION_TB+" where userId=?";
		return PermissionDao.getUserPermission(sql, userId);
	}

	@Override
	public boolean delByUserId(int userId) {
		String sql = "delete from "+Const.USER_PERMISSION_TB+" where userId=?";
		return PermissionDao.update(sql, userId);
	}

	@Override
	public boolean add(UserPermission userPermission) {
		String sql = "insert into "+Const.USER_PERMISSION_TB+"(userId,pid) values (?,?)";
		int userId = userPermission.getUserId();
		int permissionId = userPermission.getPermissionId();
		return PermissionDao.update(sql, userId,permissionId);
	}

}
